$(document).ready(function () {
    $(".drop_down").on('change', function () {
        var vs = $('.drop_down option:selected').val();
        var selected_box = $('.selected_box')
        selected_box.attr("style", "display:none")
        selected_box.eq(vs).attr("style", "display:block")
    })
    initPagination1();
});

$('#scenetab').on('click', function () {
    initPagination1();
});
$('#cardtab').on('click', function () {
    initPagination2();
});

//选项卡开始
$('.tab').on('click', function () {
    var That = $(this)
    $('.tab').attr("class", "common-text tab")
    That.attr("class", "common-text tab active")
    var m = $(this).index() / 4 * 100 + '%';
    $('.slider-container').css({
        transform: 'translateX(-' + m + ')'
    })

})
//选项卡结束
var cobject_v, tcisopen_v, ordertype_v;

//日历开始
$('#create-start').on('focus', function () {
    WdatePicker({
        //minDate:'%y-%M-{%d+1}' ,
        maxDate: '#F{$dp.$D(\'create-end\',{d:-1});}',
        onpicked: function () {
            console.log($(this).val());
        }
    })
})
$('#create-end').on('focus', function () {
    WdatePicker({
        minDate: '#F{$dp.$D(\'create-start\',{d:1});}',
        onpicked: function () {
            console.log($(this).val());
        }

    })
})
$('#first-consult-start').on('focus', function () {
    WdatePicker({
        //minDate:'%y-%M-{%d+1}' ,
        maxDate: '#F{$dp.$D(\'first-consult-end\',{d:-1});}',
        onpicked: function () {
            console.log($(this).val());
        }
    })
});
$('#first-consult-end').on('focus', function () {
    WdatePicker({
        minDate: '#F{$dp.$D(\'first-consult-start\',{d:1});}',
        onpicked: function () {
            console.log($(this).val());
        }

    })
});
$('#first-consult-start2').on('focus', function () {
    WdatePicker({
        //minDate:'%y-%M-{%d+1}' ,
        maxDate: '#F{$dp.$D(\'first-consult-end2\',{d:-1});}',
        onpicked: function () {
            console.log($(this).val());
        }
    })
})
$('#first-consult-end2').on('focus', function () {
    WdatePicker({
        minDate: '#F{$dp.$D(\'first-consult-start2\',{d:1});}',
        onpicked: function () {
            console.log($(this).val());
        }

    })
});
$('#last-consult-start').on('focus', function () {
    WdatePicker({
        //minDate:'%y-%M-{%d+1}' ,
        maxDate: '#F{$dp.$D(\'last-consult-end\',{d:-1});}',
        onpicked: function () {
            console.log($(this).val());
        }
    })
})
$('#last-consult-end').on('focus', function () {
    WdatePicker({
        minDate: '#F{$dp.$D(\'last-consult-start\',{d:1});}',
        onpicked: function () {
            console.log($(this).val());
        }

    })
})
//日历结束


$('.edit-cancel').on('click', function () {
    $("#cname_add").val('');
    $("#cobject_add").val('');
    $("#remark_add").val('');
    $("#appid_add").val('');
    $('#edit-materiala').cmsmodal('hide');
    $('#edit-materialb').cmsmodal('hide');
    $('#edit-materialc').cmsmodal('hide');
})
//场景增加 确定
function scene_add_confirm() {
    //ajax
    var cname = $("#cname_add").val();
    if (!cname) {
        alert("名称不能为空！");
        return;
    }
    var cobject_v = $("#cobject_add").val();
    var remark_v = $("#remark_add").val();
    var appid = $("#appid_add").val();
    var json1 = {
        cname: cname,
        cobject: cobject_v,
        remark: remark_v,
        appid: appid
    };

    $.ajax({

        type: "post",
        url: "/scene/add",
        data: json1,
        dataType: "json",
        success: function (data) {
            var result = data.data;
            initPagination1();
        }, error: function () {
            alert("报错了");
        }

    });

    $("#cname_add").val('');
    $("#cobject_add").val('');
    $("#remark_add").val('');
    $("#appid_add").val('');
    $('#edit-materialc').cmsmodal('hide');

}

//卡券增加确认
function confirm_card_update() {

    // 商品编辑确认
    var obj = getDivData();
    obj.tcEndTime = $('#first-consult-end').val();
    if (!obj.tcName) {
        alert("卡券名称不能为空 ！")
        ;
        return;
    }
    if (obj.tctype == 3) {
        obj.freeTime = obj.freeTime * 100;
    }
    obj.callPrice = obj.callPrice * 100;
    if (obj.tcPublish == 0) {
        $.ajax(
            {
                type: "post",
                url: "/card/update",
                data: obj,
                dataType: "json",
                success: function (data) {
                    var result = data.data;
                    $('#edit-materialb').cmsmodal('hide');
                    initPagination2();
                }, error: function () {
                alert("报错了");
            }
            }
        );
    } else {
        $.ajax(
            {
                type: "post",
                url: "/card/check",
                data: obj,
                dataType: "json",
                success: function (data) {
                    var result = data.data;
                    if (!result) {
                        alert("输入的律师不存在！");
                        return;
                    }
                    obj.zdlscode = result;
                    if (result) {
                        $.ajax(
                            {
                                type: "post",
                                url: "/card/update",
                                data: obj,
                                dataType: "json",
                                success: function (data) {
                                    var result = data.data;
                                    $('#edit-materialb').cmsmodal('hide');
                                    initPagination2();
                                }, error: function () {
                                alert("报错了");
                            }
                            }
                        );
                    }

                }, error: function () {
                alert("报错了");
            }
            }
        );
    }
    hideDialog();
}


function scene_edit_show(obj) {
    var tbody = $(obj).parents("tbody");
    var tbodyid = tbody[0].id;
    var tr = $(obj).parents("tr");
    var cname_v = tr.find(".cname").text();//名称
    var appid_v = tr.find(".appid").text();//appid
    var cobject_v = tr.find(".cobject").text();//类型
    var remark_v = tr.find(".remark").text();//备注
    var cid_v = $(obj).attr("id-value");
    $("#cname_edit").val(cname_v);
    ;
    if (cobject_v.replace(/(^\s*)|(\s*$)/g, '') == '商业') {
        $("#cobject_edit").val(1);
    } else {
        $("#cobject_edit").val(0);
    }

    $("#remark_edit").val(remark_v);
    $("#cid_edit").val(cid_v);
    $("#appid_edit").val(appid_v);
    $('#edit-materiala').cmsmodal('show');

}


//发行商弹出框下拉事件开始
/*
 vs获取到selected选定的值 0，1，2 分别代表 法海、律师、渠道商
 */
 function publish_chg(obj) {
    var vs = $(obj).val();
    var selected_box = $('.selected_box');
    var selected_box2 = $('.selected_box2')
    selected_box.attr("style", "display:none");
    selected_box.eq(vs).attr("style", "display:block");
    selected_box2.attr("style", "display:none");
    selected_box2.eq(vs).attr("style", "display:block")
}
//发行商弹出框下拉事件结束

//产品分类下拉开始变换 元 /次
 function classification_chg(obj) {
    //var vs = $('.classification option:selected').val();
    var vs= $(obj).val();
     var company = $('.company');
    var type_mz = $('.type_mz');

    if (vs == '1') {
        type_mz.text('次数')
        company.text('次')
    } else if (vs == '2') {
        type_mz.text('次数')
        company.text("次")
    } else if (vs == '3') {
        type_mz.text('面值')
        company.text("元")
    } else if (vs == '4') {
        type_mz.text('次数')
        company.text("次")
    } else {
        company.text("类型有误")
    }
}


//弹出框下拉事件结束
//新增弹窗结束
var pxzd;//排序字段
var ordertype;//排序规则
//表格部分开始
//表格头部升序 降序
$('.sequence').on('click', function () {
    pxzd = $(this).attr("pxzd");
    if ($(this).hasClass('isup')) {
        $(this).removeClass('isup').addClass('isdown');
        //降序排序
        if (pxzd == 'tcStarTime') {
            ordertype_v = 3;//开始日期降序排序
        } else if (pxzd = 'tcEndTime') {
            ordertype_v = 4;//结束日期降序排序
        }
    } else if ($(this).hasClass('isdown')) {
        $(this).removeClass('isdown').addClass('isup');
        //升序排序
        if (pxzd == 'tcStarTime') {
            ordertype_v = 1;//开始日期升序排序
        } else if (pxzd = 'tcEndTime') {
            ordertype_v = 2;//结束日期升序排序
        }
    } else {
        $(this).siblings('.sequence').removeClass('isup').removeClass('isdown');
        $(this).addClass('isup');
        //升序排序
        if (pxzd == 'tcStarTime') {
            ordertype_v = 1;//开始日期升序排序
        } else if (pxzd = 'tcEndTime') {
            ordertype_v = 2;//结束日期升序排序
        }
    }
    initPagination2();
})

//全选按钮

$('#check-all').on('click', function () {
    $('.check-unit').prop('checked', $(this).prop('checked'))
})
//批量上架弹框开始
$('.freeze').on('click', function () {
    var num = util.getCheck($('.check-unit')).length;
    if (num == 0) {
        alert('请先选择上架卡券');
        return;
    }
    $('.freeze-quesition').html('确定要将选中的' + num + '个商品上架么?');
    $('.freeze-info').html('卡券上架后。。。。。。。。。。');
    $('#freeze-info').cmsmodal('show');

    //确定
    $('.freeze-confirm').off('click').on('click', function () {
        //选中的行
        var rows = new Array();
        $('#tbody2').find('tr').each(function () {
            //   var cells= $(this)["0"].cells;
            var tctype_value = $(this).find(".tctype")["0"].innerText;
            var check_unit_value = $(this).find(".check-unit")["0"].checked;
            var tcid_value = $(this).find(".tcid")["0"].innerText;
            if (check_unit_value == true) {
                var row = {tctype: tctype_value, tcid: tcid_value};
                $.ajax(
                    {
                        type: "post",
                        url: "/card/batchOnSale",
                        traditional: true,//这里设置为true
                        data: row,
                        dataType: "json",
                        success: function (data) {
                            initPagination2();
                        }, error: function () {
                        alert("报错了");
                    }
                    }
                );
            }
        });

        $('#check-all').removeAttr("checked");
        $('#freeze-info').cmsmodal('hide');
    })
    //取消
    $('.freeze-cancel').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
})
//批量上架弹框结束

//批量下架弹框开始
$('.unfreeze').on('click', function () {
    var num = util.getCheck($('.check-unit')).length;
    if (num == 0) {
        alert('请先选择要下架的商品');
        return;
    }
    $('.freeze-quesition').html('确定要将选中的' + num + '个卡券下架么?');
    $('.freeze-info').html('卡券下架后，用户将不能继续购买该卡券。');
    $('#freeze-info').cmsmodal('show');

    //确定
    $('.freeze-confirm').off('click').on('click', function () {
        //选中的行
        var rows = new Array();
        $('#tbody2').find('tr').each(function () {
            //   var cells= $(this)["0"].cells;
            var tctype_value = $(this).find(".tctype")["0"].innerText;
            var check_unit_value = $(this).find(".check-unit")["0"].checked;
            var tcid_value = $(this).find(".tcid")["0"].innerText;
            if (check_unit_value == true) {
                var row = {tctype: tctype_value, tcid: tcid_value};
                $.ajax(
                    {
                        type: "post",
                        url: "/card/batchDownSale",
                        traditional: true,//这里设置为true
                        data: row,
                        dataType: "json",
                        success: function (data) {
                            initPagination2();
                        }, error: function () {
                        alert("报错了");
                    }
                    }
                );
            }
        });
        $('#check-all').removeAttr("checked");
        $('#freeze-info').cmsmodal('hide');
    })
    //取消
    $('.freeze-cancel').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
})
//批量下架弹框结束
//单个商品上架开始
$('.up-btn').on('click', function () {
    $('.freeze-quesition').html('确定上架该卡券么?');
    $('.freeze-info').html('卡券上架后。。。。。。。。');
    $('#freeze-info').cmsmodal('show');

    //确定
    $('.freeze-confirm').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
    //取消
    $('.freeze-cancel').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
})
//单个商品上架结束

//单个商品下架开始
$('.down-btn').on('click', function () {
    $('.freeze-quesition').html('确定下架该商品么?');
    $('.freeze-info').html('卡券下架后，用户将不能继续购买该卡券。');
    $('#freeze-info').cmsmodal('show');

    //确定
    $('.freeze-confirm').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
    //取消
    $('.freeze-cancel').off('click').on('click', function () {
        $('#freeze-info').cmsmodal('hide');
    })
})
//单个商品下架结束
var cobject_v, tctype_v, tcisopen_v;

$('#cobject_select').on('change', function () {
    cobject_v = $(this).val();
    initPagination1();
});
$('#tctype_select').on('change', function () {
    tctype_v = $(this).val();


    initPagination2();
});
$('#tcisopen_select').on('change', function () {
    tcisopen_v = $(this).val();
    initPagination2();
});
//新增弹窗结束

//分页
function initPagination1() {
    // 创建分页
    //获取总行数
    var totalcount = getCount1();
    //按照下标进行查询
    $("#Pagination1").pagination(totalcount, {
        num_edge_entries: 0, //边缘页数
        num_display_entries: 8, //主体页数
        callback: pageselectCallback1, //回调函数
        items_per_page: 10, //每页显示10项
        prev_text: "上一页",
        next_text: "下一页",
        ellipse_text: "...",//省略的文本
        prev_show_always: true,//是否总显示“前一页”分页按钮
        next_show_always: true,//是否总显示“下一页”分页按钮，
    });
};


//分页
function initPagination2() {
    // 创建分页
    //获取总行数
    var totalcount = getCount2();

    //按照下标进行查询
    $("#Pagination2").pagination(totalcount, {
        num_edge_entries: 0, //边缘页数
        num_display_entries: 8, //主体页数
        callback: pageselectCallback2, //回调函数
        items_per_page: 10, //每页显示10项
        prev_text: "上一页",
        next_text: "下一页",
        ellipse_text: "...",//省略的文本
        prev_show_always: true,//是否总显示“前一页”分页按钮
        next_show_always: true,//是否总显示“下一页”分页按钮，
    });
};

function pageselectCallback1(page_index, jq) {
    query1(page_index, jq);
}

function pageselectCallback2(page_index, jq) {
    query2(page_index, jq);
}


function cleanDiv_card_add() {
    $("#addDialog_card_edit input").each(function () {
        $(this).val('');
    });
    $("#addDialog_card_edit textarea").each(function () {

        $(this).val('');

    });
    $("#addDialog_card_edit select").each(function () {
        $(this).val('');
    });
    $("#addDialog_card input").each(function () {
        $(this).val('');
    });
    $("#addDialog_card textarea").each(function () {

        $(this).val('');
    });
    $("#addDialog_card select").each(function () {
        $(this).val('');
    });
}

//将数据转换成json

function getDivData() {
    var obj = {
        tcName: '',
        tctype: '',
        freeTime: '',
        publishNum: '',
        tcPublish: '',
        tcSn: '',
        callPrice: '',
        lawyername: '',
        lawyerPhone: '',
        tcStarTime: '',
        tcEndTime: '',
        tcRemark: '',
        zdlscode: '',
        tcid: '',
        tcTag: ''

    };

    $("#addDialog_card_edit input").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this).val();
        obj[input_n] = input_v;
    });
    $("#addDialog_card_edit textarea").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this).val();
        obj[input_n] = input_v;
    });
    $("#addDialog_card_edit select").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this)["0"].value;
        obj[input_n] = input_v;
        if (input_n == 'tctype') {
            input_n = 'tcSn';
        }
    });
    return obj
}


function getDivData_card_add() {
    var obj = {
        tcName: '',
        tctype: '',
        freeTime: '',
        publishNum: '',
        tcPublish: '',
        tcSn: '',
        callPrice: '',
        lawyername: '',
        lawyerPhone: '',
        tcStarTime: '',
        tcEndTime: '',
        tcRemark: '',
        zdlscode: '',
        tcid: '',
        tcTag: '',
        bak: '',
        proid:''
    };
    $("#addDialog_card input").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this).val();
        obj[input_n] = input_v;
    });
    $("#addDialog_card select").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this).val();
        obj[input_n] = input_v;
    });
    $("#addDialog_card textarea").each(function () {
        var input_n = $(this).attr("name");
        var input_v = $(this).val();
        obj[input_n] = input_v;
    });
    obj.tcSn = $('#tcSn_add').val();
    return obj
}

function setDivData(obj) {
    $("#addDialog_card_edit input").each(function () {
        var input_n = $(this).attr("name");
        if (input_n == 'publishNum') {
            var n = obj["'" + input_n + "'"];
            if (n == '不限量') {
                $(this).val('-1');
            } else {
                $(this).val(obj["'" + input_n + "'"]);
            }
        } else if (input_n == 'bak') {
            var v = obj["'" + input_n + "'"];
            $(this).val(obj["'bak'"]);
        } else {
            $(this).val(obj["'" + input_n + "'"]);
        }

    });
    $("#addDialog_card_edit textarea").each(function () {
        var input_n = $(this).attr("name");
        $(this).val(obj["'" + input_n + "'"]);
    });
    $("#addDialog_card_edit select").each(function () {
        var input_n = $(this).attr("name");
        if (input_n == 'tcPublish') {
            if (obj["'" + input_n + "'"] == '法海赋能网络科技有限公司') {
                $("#tcPublish_s").val(0);
                var vs = 0;
                var selected_box = $('.selected_box')
                selected_box.attr("style", "display:none")
                selected_box.eq(vs).attr("style", "display:block")
            } else {
                var vs = 1;
                $("#tcPublish_s").val(1);
                var selected_box = $('.selected_box')
                selected_box.attr("style", "display:none")
                selected_box.eq(vs).attr("style", "display:block")
            }

        }
        if (input_n = 'tctype') {
            var vs = obj["'tctype'"]
            var company = $('.company');
            var type_mz = $('.type_mz');

            type_mz.text('次数')
            company.text('次')

            if (vs == '1') {
                type_mz.text('次数')
                company.text('次')
            } else if (vs == '2') {
                type_mz.text('次数')
                company.text("次")
            } else if (vs == '3') {
                type_mz.text('面值')
                company.text("元")
            } else if (vs == '4') {
                type_mz.text('次数')
                company.text("次")
            } else {
                company.text("类型有误")
            }
            $('#tctype_edit').val(vs);
        }


    });

    $('#first-consult-end').val(obj["'tcEndTimeStr'"].substr(0, 10));
    $('#first-consult-start').val(obj["'tcStarTime'"].substr(0, 10));
}
function query1(page_index, jq) {


    if (typeof(page_index) == "undefined") {
        page_index = 0;
    }

    //发送ajax;
    //  var selefrom=$("#seek-box").serialize();

    cobject_v = $('#cobject_select').val();
    var selefrom = {
        cobject: cobject_v,
        pageNum: page_index + 1
    };

    $.ajax(
        {
            type: "post",
            url: "/scene/query",
            data: selefrom,
            dataType: "json",
            success: function (data) {
                var result = data.data;
                for (x in result.result) {
                    if (result.result[x].cobject == '1') {
                        result.result[x].cobject = '商业';
                    }
                    if (result.result[x].cobject == '0') {
                        result.result[x].cobject = '公益';
                    }
                }
                var tmpl = bt('listtmp1', result);
                document.getElementById('tbody1').innerHTML = tmpl;
            }, error: function () {
            alert("报错了");
        }
        }
    );

    //按照下标进行查询

}

function query2(page_index, jq) {


    if (typeof(page_index) == "undefined") {
        page_index = 0;
    }

    //发送ajax;
    //  var selefrom=$("#seek-box").serialize();
    var selefrom = {
        tcisopen: tcisopen_v,
        tctype: tctype_v,
        ordertype: ordertype_v,
        pageNum: page_index + 1
    };

    $.ajax(
        {
            type: "post",
            url: "/card/query",
            data: selefrom,
            dataType: "json",
            success: function (data) {
                var result = data.data;
                for (x in result.result) {

                    if (result.result[x].tcisopen == '0') {
                        result.result[x].tcisopen = '停售';
                    }
                    if (result.result[x].tcisopen == '1') {
                        result.result[x].tcisopen = '在售';
                    }
                    if (result.result[x].publishNum == '-1') {
                        result.result[x].publishNum = '不限量';
                    }

                    if (result.result[x].tctype == 3) {
                        result.result[x].freeTime = Math.round(result.result[x].freeTime) / 100;

                    }

                    result.result[x].callPrice = Math.round(result.result[x].callPrice) / 100;


                }
                var tmpl = bt('listtmp2', result);
                document.getElementById('tbody2').innerHTML = tmpl;
                var tcEndTimeStrs = $('.tcEndTimeStr');
                var publishNums = $('.publishNum');
                var publishUnums = $('.publishUnum');

                for (i = 0; i < tcEndTimeStrs.length; i++) {
                    var tr = $(tcEndTimeStrs[i]).parent("tr");
                    var v = tcEndTimeStrs[i].innerHTML;
                    var now = new Date;
                    var d = new Date(v);
                    if (result.result[i].tctype == 1 || result.result[i].tctype == 2) {
                        if (now > d) {
                            $(tcEndTimeStrs[i]).parent("tr").css("color", "red");
                        }

                    } else {
                        var vnum = tr.find(".publishNum")["0"].innerText;
                        var vunum = tr.find(".publishUnum")["0"].innerText;
                        if (parseInt(vnum) <= parseInt(vunum)) {
                            tr.css("color", "red");
                        }
                    }
                }


            }, error: function () {
            alert("报错了");
        }
        }
    );

    //按照下标进行查询

}
function getCount1() {
    var result = 0;

    var selefrom = {};

    $.ajax(
        {
            type: "post",
            url: "/scene/count",
            data: selefrom,
            dataType: "json",
            async: false,
            success: function (data) {
                result = data.data;

            }, error: function () {
            alert("报错了");
        }
        }
    );
    return result;
}

function getCount2() {
    var result = 0;


    //发送ajax;
    //  var selefrom=$("#seek-box").serialize();
    var selefrom = {
        tcisopen: tcisopen_v,
        tctype: tctype_v
    };

    $.ajax(
        {
            type: "post",
            url: "/card/count",
            data: selefrom,
            dataType: "json",
            async: false,
            success: function (data) {
                result = data.data;

            }, error: function () {
            alert("报错了");
        }
        }
    );
    return result;
}



function scene_edit_confirm() {

    var cname_v = $("#cname_edit").val();
    if (!cname_v) {
        alert("名称不能为空");
        return;
    }
    cobject_v = $("#cobject_edit").val();
    var remark_v = $("#remark_edit").val();
    var cid_v = $("#cid_edit").val();
    var appid_v = $("#appid_edit").val();
    var json1 = {
            cname: cname_v,
            cobject: cobject_v,
            remark: remark_v,
            appid: appid_v,
            cid: cid_v
        }
    ;
    $.ajax({
        type: "post",
        url: "/scene/update",
        data: json1,
        dataType: "json",
        success: function (data) {
            var result = data.data;
            $('#edit-materiala').cmsmodal('hide');
            $("#cid_edit").val('');
            $("#cname_edit").val('');
            $("#remark_edit").val('');
            json1 = {};
            initPagination1();
        }, error: function () {
            json1 = {};
            alert("报错了");
        }
    });
}
function card_edit_show(obj) {
    var tbody = $(obj).parents("tbody");
    var tbodyid = $(obj).attr("id-value");
    var tr = $(obj).parents("tr");
    var tds = tr.find("td");
    $('#tcid_edit').val(tr.find("td.tcid")["0"].innerText);
    $('#tcName_edit').val(tr.find("td.tcName")["0"].innerText);
    $('#tctype_edit').val(tr.find("td.tctype")["0"].innerText);
    $('#tcSn_edit').val(tr.find("td.tcSn")["0"].innerText);
    $('#callPrice_edit').val(tr.find("td.callPrice")["0"].innerText);
    $('#publishNum_edit').val(tr.find("td.publishNum")["0"].innerText=='不限量'?-1:tr.find("td.publishNum")["0"].innerText);
    $('#bak_edit').val(tr.find("td.bak")["0"].innerText);
    if (tr.find("td.tcPublish")["0"].innerText == '法海赋能网络科技有限公司') {
        $('#tcPublish_s').val(0);
        $('#lawyername_edit').val('');
        $('#lawyerPhone_edit').val('');
        $('.selected_box').attr("style", "display:none");
    } else {
        $('#tcPublish_s').val(1);
        $('#lawyername_edit').val(tr.find("td.lawyername")["0"].innerText);
        $('#lawyerPhone_edit').val(tr.find("td.lawyerPhone")["0"].innerText);
        $('.selected_box').attr("style", "display:block");
    }
    $('#freeTime_edit').val(tr.find("td.freeTime")["0"].innerText);
    $('#tcTag_edit').val(tr.find("td.tcTag")["0"].innerText);

    $('#first-consult-start').val(tr.find("td.tcStarTimeStr")["0"].innerText);
    $('#first-consult-end').val(tr.find("td.tcEndTimeStr")["0"].innerText);
    $('#tcRemark_edit').val(tr.find("td.tcRemark")["0"].innerText);
    //ajax获取 Production_info表的数据动态生成option
    $.ajax({
        type:"post",
        url:'/card/production',
        data:'',
        dataType:"json",
        success:function (data) {
            $('#proid_edit').html('');
            var result=data.data.result;
            for(i=0;i<result.length;i++){
                $("<option value='"+result[i].proid+"'>"+result[i].proName+"</option>").appendTo("#proid_edit");
            }
            $('#proid_edit').val(tr.find("td.proid")["0"].innerText);
            $('#proid_edit').attr("disabled","true")
        },
        error:function () {
            alert("产品加载失败！");
        }
    });

    $('#edit-materialb').cmsmodal('show');

}

function hideDialog() {
    $('#edit-materiald').cmsmodal('hide');
    $('#edit-materiala').cmsmodal('hide');
    $('#edit-materialb').cmsmodal('hide');
    $('#edit-materialc').cmsmodal('hide');
    $("#cname_add").val('');
    $("#cobject_add").val('');
    $("#remark_add").val('');
    $("#appid_add").val('');
    cleanDiv_card_add();

}

function scene_add_show() {
    $('#edit-materialc').cmsmodal('show');
}

function card_add_show() {
    var tcSn = $('.tcSn');
    $('#tctype_add').val('1');
    var selected_box2 = $('.selected_box2');
    selected_box2.attr("style", "display:none");
    $('#tcPublish_add').val(0);
    //ajax获取 Production_info表的数据动态生成option
    $.ajax({
        type:"post",
        url:'/card/production',
        data:'',
        dataType:"json",
        success:function (data) {
            $('#proid_add').html('');
            var result=data.data.result;
            for(i=0;i<result.length;i++){
                $("<option value='"+result[i].proid+"'>"+result[i].proName+"</option>").appendTo("#proid_add");
            }
        },
        error:function () {
            alert("产品加载失败！");
        }
    });

    $('#edit-materiald').cmsmodal('show');
}

//商品新增确认
function confirm_card_add() {

    //增加 ajax
    var url = "/card/add";
    var obj = getDivData_card_add();
    if (!obj.tcName) {
        alert("卡券名称不能为空 ！");
        return;
    }
    if (!obj.tcSn) {
        alert("卡券SN不能为空 ！");
        return;
    }   if (!obj.bak) {
        alert("渠道SN不能为空 ！");
        return;
    }
    if (obj.tctype == 3) {
        obj.freeTime = obj.freeTime * 100;
    }
    obj.callPrice = obj.callPrice * 100;
    //获取发行方
    if (obj.tcPublish == 0) {
        $.ajax(
            {
                type: "post",
                url: url,
                data: obj,
                dataType: "json",
                success: function (data) {
                    var result = data.data;
                    hideDialog();
                    initPagination2();
                }, error: function () {
                alert("报错了");
            }
            }
        );
    } else {
        $.ajax(
            {
                type: "post",
                url: "/card/check",
                data: obj,
                dataType: "json",
                success: function (data) {
                    var result = data.data;
                    if (!result) {
                        alert("输入的律师不存在！");
                        return;
                    }
                    obj.zdlscode = result;
                    if (result) {
                        $.ajax(
                            {
                                type: "post",
                                url: url,
                                data: obj,
                                dataType: "json",
                                success: function (data) {
                                    var result = data.data;
                                    hideDialog();
                                    initPagination2();
                                }, error: function () {
                                alert("报错了");
                            }
                            }
                        );
                    }

                }, error: function () {
                alert("报错了");
            }
            }
        );

    }
    hideDialog();


}



function checknum(obj) {

    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
}